// PasswordChecker.java
import java.util.Scanner;
import java.util.regex.Pattern;

public class PasswordChecker {

    // 至少包含一个大写字母
    private static final Pattern UPPERCASE_PATTERN = Pattern.compile(".*[A-Z].*");
    // 至少包含一个小写字母
    private static final Pattern LOWERCASE_PATTERN = Pattern.compile(".*[a-z].*");
    // 至少包含一个数字
    private static final Pattern DIGIT_PATTERN = Pattern.compile(".*\\d.*");
    // 至少包含一个特殊符号 (可以根据需要调整特殊符号的范围)
    private static final Pattern SPECIAL_CHAR_PATTERN = Pattern.compile(".*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?].*");
    // 最小长度
    private static final int MIN_LENGTH = 8;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要检查的密码: ");
        String password = scanner.nextLine();

        boolean hasUppercase = UPPERCASE_PATTERN.matcher(password).matches();
        boolean hasLowercase = LOWERCASE_PATTERN.matcher(password).matches();
        boolean hasDigit = DIGIT_PATTERN.matcher(password).matches();
        boolean hasSpecialChar = SPECIAL_CHAR_PATTERN.matcher(password).matches();
        boolean isLongEnough = password.length() >= MIN_LENGTH;

        System.out.println("\n密码强度检查结果:");
        System.out.println("长度至少 " + MIN_LENGTH + " 位: " + (isLongEnough ? "是" : "否"));
        System.out.println("包含大写字母: " + (hasUppercase ? "是" : "否"));
        System.out.println("包含小写字母: " + (hasLowercase ? "是" : "否"));
        System.out.println("包含数字: " + (hasDigit ? "是" : "否"));
        System.out.println("包含特殊符号: " + (hasSpecialChar ? "是" : "否"));

        if (isLongEnough && hasUppercase && hasLowercase && hasDigit && hasSpecialChar) {
            System.out.println("\n密码强度：强");
        } else if (isLongEnough && (hasUppercase || hasLowercase) && hasDigit) {
            System.out.println("\n密码强度：中");
        } else {
            System.out.println("\n密码强度：弱");
        }
        scanner.close();
    }
}